home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ResolveShapeFonts.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains code for the Font Handler for
- ResolveShapeFonts -- The routine that
- remaps glyphs to printer glyph codes
- and child fonts.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1991-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include <MacMemory.h>
- #include <String.h>
- #include "GXToPSBuildConfig.h"
- #include <GXExceptions.h>
- #include "IOUtilities.h"
- #include "GXPrintingUniverse.h"
- #include <Collections.h>
-
- #include "FontDatabase.h"
- #include "FontHandler.h"
- #include "FontHandlerPrivate.h"
- #include "FontHandlerVariations.h"
- #include "GXGraphics.h"
- #include "GXLayout.h"
-
-
- /*** Constants for which workspace handles will be used for what data ***/
- #define kStyleHandle 0
- #define kRunHandle 1
- #define kTextHandle 2
- #define kGlyphHandle 3
- #define kEncodedGlyphHandle 4
-
- #define kUnTaggedStyle -1
-
-
- #ifdef resumeLabel
- #undef resumeLabel
- #endif
- #define resumeLabel(exception)
-
- /*****************************************
-
- Function: FHMapGlyph
-
- Function takes a document font/glyph combination
- and maps it to a printer font/glyph comgination.
-
- hFHRec: --> Handle to the font handler record.
- theFont: --> document font reference.
- theGlyph: --> document glyph ID.
- printerIndex: <-- printer font index to use.
- printerCode: <-- printer code to use.
- twoByteCode <-- One or two byte code?
-
- If this returns collectionItemNotFoundErr or
- collectionIndexRangeErr than it means the
- there is no record of this glyph in this
- font in the printer-font records. The
- glyph must have been added during imaging
- time. The client should handle this.
-
- ******************************************/
- OSErr FHMapGlyph(TFontHandlerHdl hFHRec, fhFont theFont, short theGlyph, long *printerIndex, short *printerCode, Boolean *twoByteCode);
- OSErr FHMapGlyph(TFontHandlerHdl hFHRec, fhFont theFont, short theGlyph, long *printerIndex, short *printerCode, Boolean *twoByteCode)
- {
- OSErr status;
- TPrinterFontRec *printerFont; // a pointer to a printer font record.
- Boolean found; // Found the glyph?
- short prIndex; // printer font index.
- long offset; // Offset into data for printer font.
-
- /***** Find the printer font that contains this glyph ******/
-
- prIndex = -1;
- do {
-
- /*** Get the next printer font for this document font ***/
-
- ++prIndex;
- status = FHGetIndexedPrinterFont(hFHRec, theFont, prIndex, &printerFont, &offset); // watch for bug: if hFHRec moves, printerFont is invalid
- nrequire(status, failed_GetItem);
-
- /** Check to see if this glyph is in this printer font **/
-
- found = BITTST(printerFont->glyphUsage, theGlyph);
-
- } while (!found);
-
- /***** If the glyph is in a font that cannot be handled by the printer return appropriate error ****/
-
- if (printerFont->info & fontCantBeUsed)
- return(no_outline_font_found);
-
- /***** We found the glyph, get the printer code ******/
-
- *printerIndex = prIndex;
-
- if (printerFont->info & fontCantBeRencoded) {
-
- unsigned short *charCodes = (unsigned short*)*(printerFont->glyphToCharCodeMap);
- *printerCode = charCodes[theGlyph];
-
- if (*printerCode & 0xFF00)
- *twoByteCode = true; // First byte of short is non-zero, means 2 bytes.
- else
- *twoByteCode = false;
-
- } else {
-
- *printerCode = FHGetGlyphHash(theGlyph, printerFont->printerFontCodes);
-
- if (printerFont->info & fontIsTwoByteMember) {
-
- /** Make two byte code by combining printerIndex and printerCode **/
-
- *twoByteCode = true;
- *printerCode |= (prIndex << 8);
- *printerIndex = kTwoByteGroupIndex;
-
- } else {
-
- *twoByteCode = false;
-
- }//end if
-
- }//end if
-
- failed_GetItem:
-
- #if DEBUGLEVEL > 1
- if (status != noErr) {
- long dbIndex;
- dprintf( trace, "couldn't map, theFont: %d theGlyph: %d", theFont, theGlyph);
- dprintf( trace, "Real font: %d, dbIndex: %d", FHGetSnapShotFont(hFHRec, theFont, &dbIndex), dbIndex);
- dprintf(notrace, "If you are not running an extension, then this is a bug");
- }//end if
- #endif
-
- return(status);
-
- }//FHMapGlyph
-
-
- //<FF>
- /*************************************************
-
- Function FHSetTextTag:
-
- Function adds the tag to the shape containing the
- printer mapped text data and the bit array for 1or2 byte codes.
-
- **************************************************/
- OSErr FHSetTextTag(gxShape theShape, unsigned char *textData, long size, unsigned long *twoBits, long nChars);
- OSErr FHSetTextTag(gxShape theShape, unsigned char *textData, long size, unsigned long *twoBits, long nChars)
- {
- gxTag theTag;
-
- theTag = GXNewTag(fhTextDataTag, size, textData);
- GXSetShapeTags(theShape, fhTextDataTag, 0, 0, 1, &theTag);
- GXDisposeTag(theTag);
-
- if (twoBits != nil) {
-
- theTag = GXNewTag(fh1or2byteTag, 4 * ( (nChars + 31) / 32 ), twoBits);
- GXSetShapeTags(theShape, fh1or2byteTag, 0, 0, 1, &theTag);
- GXDisposeTag(theTag);
-
- }//end if
-
- return(GXGetGraphicsError(nil));
-
- }//FHSetTextTag
-
-
-
- //<FF>
- /*************************************************
-
- Function: FHAddStyleRun:
-
- Function adds a style run to the array of styles
- and style runs. Grows handles if necessary.
-
- hFHRec: Font handler record handle.
- theStyle: A style to add.
- index: index of style to add. (0based)
-
- **************************************************/
- OSErr FHAddStyleRun(TFontHandlerHdl hFHRec, gxStyle theStyle, long index);
- OSErr FHAddStyleRun(TFontHandlerHdl hFHRec, gxStyle theStyle, long index)
- {
- OSErr status;
- Handle h;
- gxStyle *aStyle;
- short *aRun;
-
- status = FHSetWorkHandleSize(hFHRec, (index + 1) * sizeof(gxStyle), kStyleHandle, nil);
- nrequire(status, failed_0);
-
- h = (*hFHRec)->workHandle[kStyleHandle];
-
- aStyle = (gxStyle*)(*h + index * sizeof(gxStyle));
- *aStyle = theStyle;
-
- status = FHSetWorkHandleSize(hFHRec, (index + 1) * sizeof(short), kRunHandle, nil);
- nrequire(status, failed_1);
-
- h = (*hFHRec)->workHandle[kRunHandle];
-
- aRun = (short*)(*h + index * sizeof(short));
-
- failed_1:
- failed_0:
- return(status);
-
- }//FHAddStyleRun
-
-
- //<FF>
- /**************************************
-
- Function: FHSetStylePrFontIndex
-
- Function tags a style with the printer font
- index. If there is a tag there, it replaces it.
-
- ***************************************/
- OSErr FHSetStylePrFontIndex(gxStyle theStyle, long printerFontIndex);
- OSErr FHSetStylePrFontIndex(gxStyle theStyle, long printerFontIndex)
- {
- OSErr status;
- gxTag theTag;
-
- theTag = GXNewTag(prFontIndexTag, 4, &printerFontIndex);
-
- if (GXGetStyleTags(theStyle, prFontIndexTag, 1, 1, nil) ) {
-
- GXSetStyleTags(theStyle, prFontIndexTag, 1, 1, 1, &theTag);
-
- } else {
-
- GXSetStyleTags(theStyle, prFontIndexTag, 0, 0, 1, &theTag);
-
- }//end if
-
- GXDisposeTag(theTag);
-
- status = GXGetGraphicsError(nil);
-
- return(status);
-
- }//FHSetStylePrFontIndex
-
-
- /****************************************
-
- Function: FHInitStylePrFontIndex
-
- Function initializes the printer font index tag
- on a style to kUnTaggedStyle.
-
- *****************************************/
- OSErr FHInitStylePrFontIndex(gxStyle theStyle);
- OSErr FHInitStylePrFontIndex(gxStyle theStyle)
- {
- OSErr status;
- status = FHSetStylePrFontIndex(theStyle, kUnTaggedStyle);
-
- return(status);
-
- }//FHInitStylePrFontIndex
-
-
- //<FF>
- /*************************************************
-
- Function: FHResolveGlyphShape
-
- Resolve the codes and fonts for a glyph shape.
-
- **************************************************/
- OSErr FHResolveGlyphShape(TFontHandlerHdl hFHRec, gxShape theShape);
- OSErr FHResolveGlyphShape(TFontHandlerHdl hFHRec, gxShape theShape)
- {
- OSErr status;
- register short idx;
- short *pRuns, *pRunLength;
- gxStyle *pStyles, *walkStyles;
- gxStyle shapeStyle, aStyle;
- unsigned char *textData;
- unsigned char *newTextData, *inNewTextData;
- short *pGlyphCodes, newCode;
- unsigned short *pRunGlyphs;
- Handle h, hStyles, hRuns; // new runs and styles.
- long size;
- long nChars, nRuns, byteCount, /*charCounter,*/ newRunIndex, totalRuns;
- long i, j, prFontIndex, lastPrIndex;
- Boolean twoByteCode;
- unsigned long *pTwoByteGlyphBits; // bit array for 1 or 2 byte printer codes.
- unsigned long *inTwoByteBits; // Pointer into bit array.
- unsigned long twoByteMask; // Mask for making bit array.
- gxShapeAttribute theAttributes;
- fhFont theFont;
- gxFont theRealFont;
- gxFontPlatform thePlatform;
- gxFontLanguage theLanguage;
- gxFontScript theScript;
-
- shapeStyle = GXGetShapeStyle(theShape);
- theAttributes = GXGetShapeAttributes(theShape);
-
- /**** Get the glyph data into our handle ****/
- byteCount = GXGetGlyphs(theShape, &nChars, nil, nil, nil, nil, &nRuns, nil, nil);
-
- size = byteCount + // For source text data;
- nRuns * (
- sizeof(short) + // for source runs
- sizeof(gxStyle) // for source styles
- ) +
- nChars * (
- sizeof(short) + // for new encoded glyphs.
- sizeof(short) + // for glyph code data from ApplyFontEncoding
- 4*((nChars + 31) / 32) // for 1or2byte bit array
- );
-
- status = FHSetWorkHandleSize(hFHRec, size, kTextHandle, &h);
- nrequire(status, failed_SetSize1);
- HLockHi(h);
-
- /** Get the glyph data **/
- {
- register Ptr p = *h;
- textData = (unsigned char*)p; p += byteCount;
- pRuns = (short*)p; p += nRuns * sizeof(short);
- pStyles = (gxStyle*)p; p += nRuns * sizeof(gxStyle);
- newTextData = (unsigned char*)p; p += nChars * sizeof(short);
- pGlyphCodes = (short*)p; p += nChars * sizeof(short);
- pTwoByteGlyphBits = (unsigned long*)p;
- }
- GXGetGlyphs(theShape, nil, textData, nil, nil, nil, nil, pRuns, pStyles);
-
- /** Initialize size for new styles and runs to be current style and run size **/
-
- status = FHSetWorkHandleSize(hFHRec, nRuns * sizeof(gxStyle), kStyleHandle, &hStyles);
- nrequire(status, failed_SetSize2);
-
- status = FHSetWorkHandleSize(hFHRec, nRuns * sizeof(short), kRunHandle, &hRuns);
- nrequire(status, failed_SetSize3);
- HLock(hRuns);
-
- /** Make sure each style has an initial printer font index **/
- walkStyles = pStyles;
- for (idx = nRuns - 1; idx >= 0; --idx) {
-
- aStyle = *walkStyles++;
- if (aStyle == nil)
- aStyle = shapeStyle;
-
- status = FHInitStylePrFontIndex(aStyle);
- nrequire(status, failed_InitStyles);
-
- }//end for
-
- /****************************************
- Re Encode each style run,
- Generate new runs if necessary because
- of child fonts
- *****************************************/
- //charCounter = 1;
- size = 0;
- inNewTextData = newTextData;
- inTwoByteBits = pTwoByteGlyphBits;
- twoByteMask = 0x80000000;
- totalRuns = 0;
-
- for (i = 0; i < nRuns; ++i) {
-
- /*** Make sure the data for this style run is in glyph platform ***/
- if (*pStyles == nil)
- *pStyles = shapeStyle;
-
-
- status = _FontHandlerGetStyleFont((TFontHandlerContext)hFHRec, *pStyles, &theFont);
- nrequire(status, failed_FHGetFont);
-
- theRealFont = FHgxGetStyleFont(*pStyles);
- thePlatform = GXGetStyleEncoding(*pStyles, &theScript, &theLanguage);
-
- if ( (!(theAttributes & gxIgnorePlatformShape )) && (thePlatform != gxGlyphPlatform) ) {
-
- long idx, byteLen, glyphsEncoded;
-
- pRunGlyphs = (unsigned short*) pGlyphCodes;
- idx = GXFindFontEncoding(theRealFont, thePlatform, theScript, theLanguage);
- check(idx);
-
- byteLen = *pRuns * 2;
- glyphsEncoded = GXApplyFontEncoding(theRealFont, idx, &byteLen, textData, *pRuns, pRunGlyphs, nil);
- check(glyphsEncoded == *pRuns);
-
- textData += byteLen; // Increment pointer to next run of text.
-
- } else {
-
- pRunGlyphs = (unsigned short*)textData; // data is already in glyph format.
- textData += *pRuns * sizeof(short); // Increment pointer to next run of text.
-
- }//end if
-
- /**** Now the data for this run is in glyphPlatform and pointed to by pRunGlyphs ******/
-
- lastPrIndex = FHGetStylePrFontIndex(*pStyles); // Initialize last to current.
-
- newRunIndex = 0; // newRunIndex is the index of the new run based on original
- for (j = 0; j < *pRuns; ++j) {
-
- status = FHMapGlyph(hFHRec, theFont, *pRunGlyphs++, &prFontIndex, &newCode, &twoByteCode);
- nrequire(status, failed_MapGlyph);
-
- /** Put the recoded data into the block **/
-
- if (twoByteCode) {
-
- *(short*)inNewTextData = newCode;
- inNewTextData += sizeof(short);
- size += sizeof(short);
- *inTwoByteBits |= twoByteMask; // turn on bit for two-byte code.
-
- } else {
-
- *inNewTextData++ = (unsigned char)newCode;
- ++size;
- *inTwoByteBits &= ~twoByteMask; // turn off bit for two byte mask.
-
- }//end if
-
- /** Advance the two byte mask and pointer **/
- if ( (twoByteMask >>= 1) == 0) {
- twoByteMask = 0x80000000;
- ++inTwoByteBits;
- }//end if
-
- /** Now see if we need start a mew run because printer font index changed **/
- /** or first time in loop for this run **/
-
- if ( (prFontIndex != lastPrIndex) || (j == 0) ) {
-
- /*************
- If the index is the same or the style is as yet untagged for this shape
- then use the style as is, otherwise we need to make a copy of the new
- one and tag it.
- **************/
- if ( (prFontIndex == lastPrIndex) || (lastPrIndex == kUnTaggedStyle) )
- aStyle = GXCloneStyle(*pStyles);
- else
- aStyle = GXCopyToStyle(nil, *pStyles);
-
-
- /** Add the new run to our array of runs and styles **/
- HUnlock(hRuns); // Unlock it so it can grow.
- status = FHAddStyleRun(hFHRec, aStyle, newRunIndex + totalRuns);
- nrequire(status, failed_AddRun);
- HLock(hRuns); // relock it so we can point into it.
-
- pRunLength = (short*)(*hRuns) + newRunIndex + totalRuns; // Point to this run.
- *pRunLength = 1; // Initialize it to 1.
- ++newRunIndex;
-
- if (prFontIndex != lastPrIndex) {
-
- status = FHSetStylePrFontIndex(aStyle, prFontIndex);
- nrequire(status, failed_TagStyle);
- lastPrIndex = prFontIndex;
-
- }//end if
-
- } else { // printer font index stayed same, build up this run.
-
- *pRunLength += 1;
-
- }//end if
-
- }//end for
-
- totalRuns += newRunIndex; // Add the number of new runs generated for this run to the total
- //charCounter += *pRuns; // increment charCounter for next call to GetGlyphParts.
- ++pStyles;
- ++pRuns;
-
- }//end for
-
- /** Put the new runs and styles in the glyph shape **/
-
- hStyles = (*hFHRec)->workHandle[kStyleHandle];
- hRuns = (*hFHRec)->workHandle[kRunHandle];
-
- //dprintf(notrace, "chars: %d, runs: %X", nChars, *hRuns);
-
- /** In case gx graphics moves memory **/
-
- HLock(hStyles);
- HLock(hRuns);
-
- GXSetGlyphParts(theShape, 1, nChars, nChars, nil, nil, nil, nil, (short*)*hRuns, (gxStyle*)*hStyles);
-
- /** Since SetGlyphParts increments owner counts, dispose of all styles we passed in **/
- walkStyles = (gxStyle*)*hStyles;
- for (idx = totalRuns - 1; idx >= 0; --idx)
- GXDisposeStyle(*walkStyles++);
-
-
- /** Put the tag on the shape containing the bytes for PostScript **/
-
- status = FHSetTextTag(theShape, newTextData, size, pTwoByteGlyphBits, nChars);
- ncheck(status);
-
- failed_TagStyle:
- failed_AddRun:
- failed_MapGlyph:
- failed_InitStyles:
- failed_FHGetFont:
-
- FHReleaseWorkspace(hFHRec, kRunHandle);
-
- failed_SetSize3:
-
- FHReleaseWorkspace(hFHRec, kStyleHandle);
-
- failed_SetSize2:
-
- FHReleaseWorkspace(hFHRec, kTextHandle);
-
- failed_SetSize1:
-
- return(status);
-
- }//FHResolveGlyphShape
-
-
-
- //<FF>
- /*************************************************
-
- Function: FHResolveTextShape
-
- Resolve the codes and fonts for a text shape.
-
- **************************************************/
- OSErr FHResolveTextShape(TFontHandlerHdl hFHRec, gxShape theShape);
- OSErr FHResolveTextShape(TFontHandlerHdl hFHRec, gxShape theShape)
- {
- OSErr status;
- long size; // Number of bytes in text shape.
- Handle hStyles;
- Handle hRuns;
- Handle hText;
- Handle hGlyphs;
- Handle newGlyphs;
- long runIndex;
- short *runLength; // Pointer into handle of run lengths;
- gxStyle aStyle, theStyle;
- long charCount;
- long idx;
- long prFontIndex; // Printer font index for the glyph.
- long lastPrIndex;
- short newCode;
- unsigned char *pText, *pNewText;
- unsigned short *pGlyphs;
- fhFont theFont;
- Boolean twoByteCode;
- unsigned long *pTwoByteGlyphBits; // bit array for 1 or 2 byte printer codes.
- unsigned long *inTwoByteBits; // Pointer into bit array.
- unsigned long twoByteMask; // Mask for making bit array.
- gxFontPlatform thePlatform;
- gxFontScript theScript;
- gxFontLanguage theLanguage;
- long dataSize; // Size of new text data.
-
- size = GXGetText(theShape, &charCount, nil, nil);
- if (size == 0) return(noErr);
-
- /** Size > 0, process the text **/
-
- theStyle = GXGetShapeStyle(theShape);
-
- status = _FontHandlerGetStyleFont((TFontHandlerContext)hFHRec, theStyle, &theFont);
- nrequire(status, failed_FHGetFont);
-
- thePlatform = GXGetStyleEncoding(theStyle, &theScript, &theLanguage);
-
- /** Handle for the shape's text and 1or2 byte bit array **/
- status = FHSetWorkHandleSize(hFHRec, size + 4 * ( (charCount + 31) / 32), kTextHandle, &hText);
- nrequire(status, failed_SetSize1);
-
- /** Handle for the glyph codes if it is not alread in glyph code format **/
- if (thePlatform != gxGlyphPlatform) {
-
- status = FHSetWorkHandleSize(hFHRec, charCount * sizeof(short), kGlyphHandle, &hGlyphs);
- nrequire(status, failed_SetSize1);
- HLock(hGlyphs);
-
- }//end if
-
- /** Handle for the new encoded glyphs for the tag **/
- status = FHSetWorkHandleSize(hFHRec, 2 * charCount, kEncodedGlyphHandle, &newGlyphs);
- nrequire(status, failed_SetSize2);
-
- hRuns = (*hFHRec)->workHandle[kRunHandle];
- hStyles = (*hFHRec)->workHandle[kStyleHandle];
- HLock(newGlyphs);
- HLock(hText);
-
- /** Get the text data **/
- pText = (unsigned char*)*hText;
- pTwoByteGlyphBits = (unsigned long*)(pText + size);
- GXGetText(theShape, nil, pText, nil);
-
- /** Convert it all to glyph codes **/
- if (thePlatform != gxGlyphPlatform) {
-
- long byteLen = size;
- gxFont theRealFont;
-
- theRealFont = FHGetSnapShotFont(hFHRec, theFont, nil);
-
- pGlyphs = (unsigned short*)*hGlyphs;
- idx = GXFindFontEncoding(theRealFont, thePlatform, theScript, theLanguage);
- check(idx);
- dataSize = GXApplyFontEncoding(theRealFont, idx, &byteLen, pText, charCount, pGlyphs, nil );
- check(dataSize == charCount);
-
- } else {
-
- pGlyphs = (unsigned short*)pText;
-
- }//end if
-
- /**** Generate the printer codes and style runs ****/
-
- status = FHInitStylePrFontIndex(theStyle);
- nrequire(status, failed_InitStyle);
-
- pNewText = (unsigned char*)*newGlyphs;
- runIndex = 0;
- aStyle = nil;
- dataSize = 0;
- lastPrIndex = FHGetStylePrFontIndex(theStyle);
- inTwoByteBits = pTwoByteGlyphBits;
- twoByteMask = 0x80000000;
-
- for (idx = 0; idx < charCount; ++idx) {
-
- status = FHMapGlyph(hFHRec, theFont, *pGlyphs, &prFontIndex, &newCode, &twoByteCode);
- nrequire(status, failed_MapGlyph);
-
- if (twoByteCode) {
-
- *(short*)pNewText = newCode;
- pNewText += sizeof(short);
- dataSize += sizeof(short);
- *inTwoByteBits |= twoByteMask; // turn on bit for two-byte code.
-
- } else {
-
- *pNewText++ = (unsigned char)newCode;
- ++dataSize;
- *inTwoByteBits &= ~twoByteMask; // turn off bit for two byte mask.
-
- }//end if
-
- /** Advance the two byte mask and pointer **/
- if ( (twoByteMask >>= 1) == 0) {
- twoByteMask = 0x80000000;
- ++inTwoByteBits;
- }//end if
-
- /** Determine if we need a new run becuase printer font index changed **/
- /** or the first time through the loop **/
-
- if ( (prFontIndex != lastPrIndex) || (idx == 0)) {
-
- if (runIndex == 0)
- aStyle = GXCloneStyle(theStyle);
- else
- aStyle = GXCopyToStyle(nil, theStyle);
-
- HUnlock(hRuns); // Unlock it so it can grow.
- status = FHAddStyleRun(hFHRec, aStyle, runIndex);
- nrequire(status, failed_AddRun);
- HLock(hRuns); // Lock it down again.
-
- runLength = (short*)(*hRuns) + runIndex; // Point into it for incrementing run length.
-
- nrequire(status = FHSetStylePrFontIndex(aStyle, prFontIndex), failed_TagStyle);
-
- lastPrIndex = prFontIndex;
- ++runIndex;
- *runLength = 1;
-
- } else {
-
- *runLength += 1;
-
- }//end if
-
- ++pGlyphs;
-
- }//end for
-
-
- /*** If more than one run was generated, make it a glyph shape ****/
-
- if (runIndex > 1) {
-
- gxStyle *pStyle;
- register short idx;
-
- hStyles = (*hFHRec)->workHandle[kStyleHandle];
- hRuns = (*hFHRec)->workHandle[kRunHandle];
-
- HLock(hStyles);
-
- GXSetShapeType(theShape, gxGlyphType);
-
- GXSetGlyphParts(theShape, 1, charCount, charCount, nil, nil, nil, nil,
- (short*)*hRuns, (gxStyle*)*hStyles);
- nrequire(status = GXGetGraphicsError(nil), failed_SetGlyphParts);
-
- /** dispose of the styles we created **/
- pStyle = (gxStyle*)*hStyles;
- for (idx = runIndex - 1; idx >= 0; --idx)
- GXDisposeStyle(*pStyle++);
-
- } else { // couldn't have even cloned it if
-
- GXDisposeStyle(theStyle); // we cloned it.
-
- }//end if
-
- /** Tag the shape with the new text and bits **/
-
- /** The 1or2 byte code bits are unnecessary if we left it a text shape, pass nil **/
- if (runIndex <= 1)
- pTwoByteGlyphBits = nil;
-
- status = FHSetTextTag(theShape, (unsigned char*)*newGlyphs, dataSize, pTwoByteGlyphBits, charCount);
- ncheck(status);
-
- failed_SetGlyphParts:
- failed_TagStyle:
- failed_AddRun:
- failed_MapGlyph:
- failed_InitStyle:
-
- FHReleaseWorkspace(hFHRec, kStyleHandle);
- FHReleaseWorkspace(hFHRec, kRunHandle);
- FHReleaseWorkspace(hFHRec, kTextHandle);
- if (thePlatform != gxGlyphPlatform) FHReleaseWorkspace(hFHRec, kGlyphHandle);
- FHReleaseWorkspace(hFHRec, kEncodedGlyphHandle);
-
-
- failed_SetSize2:
- failed_SetSize1:
- failed_FHGetFont:
-
- return(status);
-
- }//FHResolveTextShape
-
-
- //<FF>
- /*************************************************
-
- Function: FHResolveLayoutShape
-
- Resolve the codes and fonts for a layout shape.
-
- **************************************************/
- OSErr FHResolveLayoutShape(TFontHandlerHdl hFHRec, gxShape theShape);
- OSErr FHResolveLayoutShape(TFontHandlerHdl hFHRec, gxShape theShape)
- {
- OSErr status;
- gxShapeType newType;
- /**********
- Call PrimitiveShape to get a glyph shape that has layout stuff applied to it.
- SetShapeType(theShape, glyphType) would just convert the geometry to a glyph
- without applying justification or contextual forms, etc… Note: If PrimitiveShape
- on a layout ever changes to not make a shape of type glyph, this and the PostScript
- Imaging Engine will break, since the IE is also dependent on glyph shapes being
- generated.
- **********/
- GXPrimitiveShape(theShape);
- nrequire(status = GXGetGraphicsError(nil), failed_ChangeType);
-
-
- newType = GXGetShapeType(theShape);
- if (newType == gxEmptyType) {
-
- status = noErr; // Just return.
-
- } else if (newType == gxGlyphType) { // Resolve the glyph shape.
-
- status = FHResolveGlyphShape(hFHRec, theShape);
-
- } else { // This should never happen, should always be glyph or empty.
-
- #if DEBUGLEVEL > 0
- dprintf(notrace, "PrimitiveShape on layout did not generate glyph or empty shape. Fatal Error!!!!");
- #endif
- status = illegal_type_for_shape;
-
- }//end if
-
- failed_ChangeType:
- ncheck(status);
- return(status);
-
- }//FHResolveLayoutShape
-
-
- //<FF>
- #if useDEBUGTEXT
- /*******************************
- Routine: FHShowDebugText
-
- Routine outputs a PostScript comment that
- shows the text of the shape that is about
- to be resolved in its un-printer encoeded
- form so the PostScript file is more readable.
-
- This code is only in the debugging version
-
- ********************************/
- OSErr FHShowDebugText(TFontHandlerHdl hFHRec, gxShape theShape)
- {
- OSErr status;
- TRDParams rdParams;
- unsigned char *textData;
- long byteCount;
-
- rdParams.rdMap = (*hFHRec)->rdMap;
- rdParams.resType = kScriptResType;
- rdParams.resID = kFHScriptResID;
- rdParams.rdFlags = eRDnoOptions;
- rdParams.resIndex = kDebugShowText;
-
- switch(GXGetShapeType(theShape)) {
-
- case gxTextType:
- byteCount = GXGetText(theShape, nil, nil, nil);
- nrequire(status = PrNewPtr(&textData, byteCount), failed_Alloc);
- GXGetText(theShape, nil, textData, nil);
- break;
-
- case gxLayoutType:
- byteCount = GXGetLayout(theShape, nil, nil, nil, nil, nil, nil, nil, nil, nil);
- nrequire(status = PrNewPtr(&textData, byteCount), failed_Alloc);
- GXGetLayout(theShape, textData, nil, nil, nil, nil, nil, nil, nil, nil);
- break;
-
- case gxGlyphType:
- byteCount = GXGetGlyphs(theShape, nil, nil, nil, nil, nil, nil, nil, nil);
- nrequire(status = PrNewPtr(&textData, byteCount), failed_Alloc);
- GXGetGlyphs(theShape, nil, textData, nil, nil, nil, nil, nil, nil);
- break;
-
- }//end switch
-
- status = RDResPrintf(&rdParams, textData, byteCount);
- ncheck(status);
-
- (void) PrDisposePtr(textData);
-
- failed_Alloc:
- return(status);
-
- }//FHShowDebugText
- #endif
-
- //<FF>
- /*************************************************
-
- Function: FontHandlerResolveShapeFonts:
-
- Function remaps all of the glyph codes in a shape
- to printer codes. New style runs are generated if
- necessary so that styles can be tagged with child font
- indecies.
-
- context: The font handler context. (if nil, then we'll say no outline fonts are available signaling client to rasterize of pathify)
- theShape: Shape to resolve.
-
- **************************************************/
- OSErr FontHandlerResolveShapeFonts(TFontHandlerContext context, gxShape theShape)
- {
- OSErr status;
- gxShapeType theType;
- Boolean done = false;
-
- if (context == nil)
- return(no_outline_font_found);
-
- #if 0 /*** DEBUGLEVEL > 1 ****/
- status = FHShowDebugText((TFontHandlerHdl)context, theShape);
- ncheck(status);
- if (status != noErr) return(status);
- #endif
-
-
- while (!done) {
-
- theType = GXGetShapeType(theShape);
-
- switch(theType) {
-
- case gxTextType:
- status = FHResolveTextShape((TFontHandlerHdl)context, theShape);
- break;
-
- case gxGlyphType:
- status = FHResolveGlyphShape((TFontHandlerHdl)context, theShape);
- break;
-
- case gxLayoutType:
- status = FHResolveLayoutShape((TFontHandlerHdl)context, theShape);
- break;
-
- default:
- status = noErr;
-
- }//end switch
-
-
- /************************************************
- A Collection error indicates that the some glyph
- from the shape was not in any of the printer fonts.
- Build new printer fonts for this shape and try again.
- **************************************************/
- if ( (status == collectionItemNotFoundErr) || (status == collectionIndexRangeErr) ) {
-
- #if DEBUGLEVEL > 1
- dprintf(trace, "Calling FHAddNonDatabaseShape");
- #endif
- status = FHAddNonDatabaseShape((TFontHandlerHdl)context, theShape);
- nrequire(status, failed_NonDatabase);
-
- } else {
-
- done = true;
-
- }//end if
-
- }//end while
-
- failed_NonDatabase:
-
- ncheck(status);
- return(status);
-
- }//FontHandlerResolveShapeFonts
-
-